﻿using System;
using System.Threading.Tasks;

namespace 异步编程
{
	static class DoAsyncStuff
	{
		/// <summary>
		/// 异步计算和
		/// </summary>
		/// <param name="i1"></param>
		/// <param name="i2"></param>
		/// <returns></returns>
		public static async Task<int> CalculateSumAsync (int i1,int i2){
			int sum = await Task.Run(() => GetSum(i1, i2));
			return sum;
		}
		/// <summary>
		/// 求和方法
		/// </summary>
		/// <param name="i1"></param>
		/// <param name="i2"></param>
		/// <returns></returns>
		private static int GetSum(int i1, int i2) { return i1 + i2; }
	}

    class Program
    {
        static void Main(string[] args)
        {
			Task<int> value = DoAsyncStuff.CalculateSumAsync(5, 6);
			Console.WriteLine("Value:{0}",value.Result);
			Console.ReadKey();
        }
    }
}